package cn.jsu.oj.dispatchServer.handle.handles;

import cn.jsu.oj.dispatchServer.handle.CommandPack;
import cn.jsu.oj.dispatchServer.net.DispatchServerHandle;
import cn.jsu.oj.dispatchServer.parsing.HandleType;
import cn.jsu.oj.dispatchServer.pojo.StorageCmdInfo;
import cn.jsu.oj.dispatchServer.pojo.TaskInfo;
import cn.jsu.oj.dispatchServer.resource.Resource;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

/**
 * @author 24987
 */
@Slf4j
@HandleType(type = 18)
public class StorageCmdInfoHandle implements Handle{
    @Override
    public CommandPack<?> handle(CommandPack<?> pack) {
        StorageCmdInfo storageCmdInfo = (StorageCmdInfo) pack.getData();
        Map<Long, TaskInfo> taskMap = Resource.storeTaskMap.get(storageCmdInfo.getIp());
        log.info("暂存任务映射的判题机数  {}" ,Resource.storeTaskMap.size());
//        System.out.println("taskBigQueueSize-----"+Resource.taskBigQueue.size());
        Resource.storeTaskMap.forEach((a,b)->{
            log.info("storeTaskMap"+a+" "+b);
        });
//        if(taskMap!=null) {
//           taskMap.forEach((key, value) -> {
//               log.warn("Long----" + key + " " + "value----------" + value);
//           });
//        }
        if (taskMap != null) {
            //删除暂存任务
            TaskInfo info = taskMap.remove(storageCmdInfo.getSerialNumber());
            log.info("流水号:{} 移出暂存队列",storageCmdInfo.getSerialNumber());
        }
        return null;
    }
}
